#include "MainWindow.h"
#include "ui_MainWindow.h"
#include "TableTest/BaseTableTest.h"
#include "TreeTest/BaseTreeTest.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow),m_pWidget(nullptr)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}
/**
 * @brief on_pushButton_BaseTable_clicked
 * 创建基础表格
 */
void MainWindow::on_pushButton_BaseTable_clicked()
{
    if(!m_TestWidgetMap.contains(ui->pushButton_BaseTable->text()))
    {
       m_TestWidgetMap.insert(ui->pushButton_BaseTable->text(),new BaseTableTest(this));
       ui->gridLayout_DomeLayout->addWidget(m_TestWidgetMap.value(ui->pushButton_BaseTable->text()));
    }
    changeWidgetDisplay(m_TestWidgetMap.value(ui->pushButton_BaseTable->text()));
}
/**
 * @brief on_pushButton_BaseTree_clicked
 * 创建基础树
 */
void MainWindow::on_pushButton_BaseTree_clicked()
{
    if(!m_TestWidgetMap.contains(ui->pushButton_BaseTree->text()))
    {
       m_TestWidgetMap.insert(ui->pushButton_BaseTree->text(),new BaseTreeTest(this));
       ui->gridLayout_DomeLayout->addWidget(m_TestWidgetMap.value(ui->pushButton_BaseTree->text()));
    }
    changeWidgetDisplay(m_TestWidgetMap.value(ui->pushButton_BaseTree->text()));
}
/**
 * @brief changeWidgetDisplay 更改测试的控件
 * @param pWidget  新测试的控件
 */
void MainWindow::changeWidgetDisplay(QWidget* pWidget)
{
    if(nullptr!=m_pWidget)
    {
        m_pWidget->setVisible(false);
    }
    pWidget->setVisible(true);
    m_pWidget=pWidget;
}
